package com.qf.microuser.point.controller;

import com.qf.common.core.common.R;
import com.qf.common.core.entity.PointRule;
import com.qf.common.core.enums.PointTypeEnum;
import com.qf.microuser.point.service.PointRedisService;
import com.qf.microuser.point.service.PointRuleService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * --- 缘分让我们相遇乱世以外 ---
 *
 * @author SJY
 * 2024/12/30
 * 使用先删除redis缓存，再修改数据库
 */
// @RestController
// @RequestMapping("/point")
public class PointRuleController {
    @Resource
    private PointRedisService pointRedisService;
    @Resource
    private PointRuleService pointRuleService;

    /**
     * 修改积分规则
     */
    @PostMapping("/change")
    public R modify(PointRule pointRule) {
        // 先删除redis缓存
        pointRedisService.deletePoint();
        // 积分规则修改逻辑
        pointRedisService.addPointType(pointRule);
        // 数据库修改之后再次添加到redis缓存
        pointRuleService.pointRuleByType(PointTypeEnum.POINT_SIGN.getType());
        return R.ok();
    }
}
